package com.rzjm.exercise.module.controller;

import com.rzjm.exercise.common.base.data.DataTableLayUI;
import com.rzjm.exercise.common.log.annotation.Log;
import com.rzjm.exercise.common.utils.R;
import com.rzjm.exercise.module.domain.RegFireCheck;
import com.rzjm.exercise.module.service.RegFireCheckService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 动火申请
 *
 * @author mr.zhou
 * @email zhouwei_nice@163.com
 * @date 2020-12-15 22:36:23
 */
@Controller
@RequestMapping("/module/regFireCheck")
public class RegFireCheckController {
    @Resource
    private RegFireCheckService regFireCheckService;

    @Log("查询动火申请")
    @GetMapping()
    @RequiresPermissions("module:firecheck:firecheck")
    String Shop() {
        return "module/firecheck/firecheck";
    }

    @Log("查询动火申请")
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("module:firecheck:firecheck")
    public DataTableLayUI<RegFireCheck> list(DataTableLayUI<RegFireCheck> condition) {
        DataTableLayUI<RegFireCheck> dt = regFireCheckService.pageSearchLayUI(condition);
        return dt;
    }

    @Log("新增动火申请")
    @GetMapping("/add")
    @RequiresPermissions("module:firecheck:add")
    String add(Model model) {
        RegFireCheck firecheck = new RegFireCheck();
        model.addAttribute("firecheck", firecheck);
        return "module/firecheck/detail";
    }


    @Log("编辑动火申请")
    @GetMapping("/edit/{id}")
    @RequiresPermissions("module:firecheck:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        RegFireCheck firecheck = regFireCheckService.findById(id);
        model.addAttribute("firecheck", firecheck);
        return "module/firecheck/detail";
    }

    /**
     * 保存
     */
    @Log("新增动火申请")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("module:firecheck:add")
    public R save(@Valid RegFireCheck firecheck) {
        if (regFireCheckService.save(firecheck)) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("更新动火申请")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("module:firecheck:edit")
    public R update(@Valid RegFireCheck firecheck) {
        regFireCheckService.updateById(firecheck);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除动火申请")
    @PostMapping( "/remove")
    @ResponseBody
    @RequiresPermissions("module:firecheck:remove")
    public R remove( Integer id) {
        if (regFireCheckService.removeById(id)) {
            return R.ok();
        }
        return R.error();
    }
}
